package com.yjhb.android.sbz.fragment;

import android.view.View;

import com.yjhb.android.sbz.adapter.SystemNoticeAdapter;
import com.yjhb.android.sbz.entity.SystemNotice;
import com.yjhb.android.sbz.mvp.sys.SystemNoticePresenter;
import com.yjhb.android.sbz.mvp.sys.SystemNoticeView;
import com.tencent.imsdk.v2.V2TIMConversation;
import com.tencent.qcloud.tim.uikit.config.SysUserConfig;
import com.tencent.qcloud.tim.uikit.modules.chat.C2CChatManagerKit;
import com.tencent.qcloud.tim.uikit.modules.chat.base.ChatInfo;

import java.util.List;

/**
 * 创建者 zx
 * 创建时间 2021/1/11 11:13
 */
public class SystemNoticeFragment extends BaseListFragment<SystemNoticePresenter, SystemNoticeAdapter, SystemNotice> implements SystemNoticeView {
    private final String TAG = "SystemNoticeFragment";

    @Override
    protected SystemNoticeAdapter getAdapter() {
        return new SystemNoticeAdapter(getContext());
    }

    @Override
    protected void initUI() {
//        recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL,true));
        super.initUI();
    }

    @Override
    protected CharSequence getTips() {
        return null;
    }

    @Override
    protected void onLoadData(int size, int current) {
        ChatInfo chatInfo = new ChatInfo();
        chatInfo.setType(V2TIMConversation.V2TIM_C2C);
        chatInfo.setId(SysUserConfig.SYSTEM_NOTICE.getId());
        chatInfo.setChatName("系统通知");
        C2CChatManagerKit.getInstance().setCurrentChatInfo(chatInfo);
        if (current > 1 && dataSet.size() > 0)
            presenter.loadSystemNotice(dataSet.get(dataSet.size() - 1).getMessageInfo(), false);
        else
            presenter.loadSystemNotice(null, true);
    }

    @Override
    public void onDestroy() {
        C2CChatManagerKit.getInstance().destroyChat();
        super.onDestroy();
    }

    @Override
    protected SystemNoticePresenter initPresenter() {
        return new SystemNoticePresenter(this);
    }

    @Override
    public void onItemClick(int index, Object o) {

    }

    @Override
    public void onViewClick(View view, String msg, int index, Object o) {

    }

    @Override
    public void onLoad(List<SystemNotice> systemNotices, boolean isRefresh) {
        loadingDialog.cancel();
        smartRefreshLayout.finishRefresh();
        smartRefreshLayout.finishLoadmore();
        if (isRefresh) {
            dataSet.clear();
        }
        dataSet.addAll(systemNotices);
        adapter.notifyDataSetChanged();
    }
}
